package com.xgl.controller;


import com.xgl.pojo.Department;
import com.xgl.pojo.Major;
import com.xgl.pojo.RespBean;
import com.xgl.service.IMajorService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 最最帅气的熊国林
 * @since 2021-05-09
 */
@RestController
@RequestMapping("/system/basic/major")
public class MajorController {
    @Autowired
    private IMajorService majorService;

    @ApiOperation(value = "查询全部专业")
    @GetMapping("/")
    private List<Major> getAllMajor(){
        return majorService.list();
    }
//
//    @ApiOperation(value = "查询全部专业")
//    @GetMapping("/")
//    private void getAllMajor(){
//        return  majorService.showAllList();
//
//    }

    @ApiOperation(value = "添加专业信息")
    @PostMapping("/")
    private RespBean addMajor(@RequestBody Major major){
        major.setCreateDate(LocalDateTime.now());
        if (majorService.save(major)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    @ApiOperation(value = "修改专业信息")
    @PutMapping("/")
    private RespBean updateMajor(@RequestBody Major major){
        if (majorService.updateById(major)){
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }

    @ApiOperation(value = "删除专业信息")
    @DeleteMapping("/{id}")
    private RespBean deleteMajor(@PathVariable Integer id){
        if (majorService.removeById(id)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }


}
